<template lang="html">
  <div>
    <selfHeader></selfHeader>
    <div class="main">
      <div class="imageBox">
        <img :src="QRSrc" alt="" class="QR">
      </div>


      <div class="downloadBox">
        <p>用户推荐码: {{uid}}</p>
        <button data-clipboard-action="copy" class="cobyOrderSn" :data-clipboard-text="uid" @click="copyLink">点击复制</button>
      </div>

      <div class="downloadBox">
        <p>下载地址: {{download}} </p>
        <button data-clipboard-action="copy" class="cobyOrderSn" :data-clipboard-text="download" @click="copyLink">点击复制</button>
      </div>

    </div>
  </div>
</template>

<script>
import {goodUpdateTeam, QRcode} from '@/http/api'
import isEmpty from '@/components/isEmpty'
import selfHeader from '@/common/header'
import {Toast} from 'mint-ui'

export default {
  components: {
    isEmpty,
    selfHeader
  },
  data() {
    return {
      isempty: true,
      list: [],
      QRSrc: '',
      uid: '',
      download: 'http://good.hkazy.com/plfe'
    }
  },
  created() {
    this.getList()
    this.uid = JSON.parse(localStorage.getItem('UserMessage')).user.uid
  },
  methods: {
    async getList() {
      const user = JSON.parse(localStorage.getItem('UserMessage'))
      const data = {
        uid: user.user.uid
      }
      const QR = await QRcode({
        ...data,
        width: 200,
        height: 200
      })
      if (QR.code * 1 === 200) {
        this.QRSrc = QR.data.qrCode
      }
    },
    copyLink() {
      let clipboard = new this.clipboard(".cobyOrderSn");
      clipboard.on('success', function () {
        console.log('成功')
        Toast('复制成功')
      });
      clipboard.on('error', function () {
        console.log('失败')
        Toast('复制失败')
      });
    }
  }
}
</script>

<style lang="less" scoped>
.main {
  width: 100%;
  margin-top: 60px;
}

.userBox {
  padding: 0 6px;

  div {
    width: 100%;
    display: flex;
    box-sizing: border-box;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    border-bottom: 1px solid #048AB9;
    border-radius: 4px;
    overflow: hidden;

    img {
      width: 40px;
      height: 40px;
      border-radius: 20px;
    }
  }
}

.imageBox {
  width: 200px;
  display: block;
  height: 200px;
  margin: 0 auto;
  background-image: url("../assets/tea.png");
  background-size: 100% 100%;
  background-repeat: no-repeat;
  overflow: hidden;
  border-radius: 6px;

  .QR {
    width: 120px;
    height: 120px;
    margin: 40px auto;
    display: block;
    opacity: .95;
  }
}
p {
  text-align: center;
  margin-top: 6px;
}
.downloadBox {
  display: flex;
  justify-content: space-around;
}
</style>
